local M = {}

function M.setup()
  local telescope = require("telescope")
  local actions = require("telescope.actions")

  -- 基础配置
  local opts = {
    defaults = {
      color_devicons = true,
      prompt_prefix = "🔍 ",
      selection_caret = "➜ ",
      winblend = 10,
      borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
      layout_strategy = "horizontal",
      layout_config = {
        width = 0.9,
        height = 0.8,
        preview_width = 0.6
      },
      path_display = { "truncate" },
      file_ignore_patterns = { "node_modules", ".git" },
      mappings = {
        i = {
          ["<Esc>"] = actions.close, -- 自定义映射示例
        },
      },
    },
    pickers = {
      find_files = {
        hidden = true,
        no_ignore = false,
      },
    },
    extensions = {
      fzf = { -- fzf 扩展配置
        fuzzy = true,
        override_generic_sorter = true,
        override_file_sorter = true,
      }
    }
  }

  telescope.setup(opts)

  -- 加载扩展
  pcall(telescope.load_extension, "fzf")
end

-- 快捷键配置（独立函数便于管理）
function M.register_keymaps()
  local builtin = require("telescope.builtin")
  local keymap = vim.keymap.set

  keymap("n", "<leader>ff", builtin.find_files, { desc = "Find files" })
  keymap("n", "<leader>fg", builtin.live_grep, { desc = "Live grep" })
  keymap("n", "<leader>fb", builtin.buffers, { desc = "Find buffers" })
  keymap("n", "<leader>fh", builtin.help_tags, { desc = "Help tags" })
  -- 更多自定义快捷键...
end

return M
